package com.example.lotteryticketdev.tool;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class NumberCreator {
    
   private static Random random = new Random();
    
   private static String create(MyRule myRule){
        List<String> list = new ArrayList<>();
        int shi ;
        int ge ;
        //十位范围
        int scopeShi = myRule.getMax() / 10 ;
       //个位范围
        int scopeGe = myRule.getMax() % 10 ;
            //十位上的数取值 [0,3]
           /*
            * 个位上的数取值 [0,9]
            * 特殊情况1.当十位为0时个位不为0
            * 特殊情况2.当十位为3时个位不大于3
            *
            * */

       for (int i = 0; i < myRule.getLimit(); i++) {
           
           shi = random.nextInt(scopeShi+1);
           if(shi == 0){
               ge = random.nextInt(9)+1;
           }
           else if(shi == scopeShi){
               ge = random.nextInt(scopeGe)+1;
           }
           else {
               ge = random.nextInt(10);
           }

           while (list.contains( "" + shi + ge)){
               shi = random.nextInt(scopeShi+1);
               if(shi == 0){
                   ge = random.nextInt(9)+1;
               }
               else if(shi == scopeShi){
                   ge = random.nextInt(scopeGe)+1;
               }
               else {
                   ge = random.nextInt(10);
               }
           }
           list.add( "" + shi + ge);
       }

       StringBuilder sb = new StringBuilder();
       for (int i = 0; i < list.size(); i++) {
           sb.append(list.get(i));
            if(i < myRule.getLimit()-1){
                sb.append(",");
            }
       }
       return sb.toString();

    }


    public static void main(String[] args) {
        MyRule myRule = new MyRule();

        myRule.setLimit(1);
        myRule.setMax(16);
        for (int i = 0; i < 100; i++) {
            String red = create(myRule);

            System.out.println("red = " + red);
        }

    }
}
